home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / quicspool / libqmsquery / qmsquery.c < prev    next >
C/C++ Source or Header  |  1990-10-01  |  3KB  |  153 lines

  1. #ifndef lint
  2. static char *rcs = "$Header: qmsquery.c,v 1.1 88/01/15 12:19:30 simpson Rel $";
  3. #endif
  4. #include <stdio.h>
  5. #include <signal.h>
  6. #include <setjmp.h>
  7. #include <local/standard.h>
  8. #include "qms.h"
  9.  
  10. FILE    *_Ifp, *_Ofp;    /* Input and output file pointer */
  11. Boolean        _FirstChar;
  12. static int    (*OldAlarm)();    /* Saves the old SIGALRM value */
  13. static jmp_buf    Env;
  14.  
  15. int qmsopen(writefd, readfd)
  16. int writefd, readfd;
  17. {
  18.     int            timeout();
  19.  
  20.     if (!(_Ofp = fdopen(writefd, "w")))
  21.     return FALSE;
  22.     if (!(_Ifp = fdopen(readfd, "r")))
  23.     return FALSE;
  24.     setbuffer(_Ifp, (char *)NULL, 0);        /* Turn off buffering on input */
  25.     OldAlarm = signal(SIGALRM, timeout);
  26.     return TRUE;
  27. }
  28.  
  29. int qmsclose()
  30. {
  31.     (void)signal(SIGALRM, OldAlarm);
  32.     (void)fclose(_Ofp), (void)fclose(_Ifp);
  33.     return TRUE;
  34. }
  35.  
  36. int timedgetc(f)
  37. FILE    *f;
  38. {
  39.     int        c;
  40.  
  41.     /* The amount of time to wait until we have decided it is EOF is
  42.      * hard to select.  The printer does not always send the status
  43.      * information out of the debugger port upon immediately receiving the
  44.      * ^INFO command.  It will accept the ^INFO command, put it in its
  45.      * buffer, and send the status information when it finally interprets
  46.      * the ^INFO command.  I have seen it take as long as 11 seconds
  47.      * between the time the ^INFO command was sent and the time the status
  48.      * information is sent out the debugger port.  We don't want to wait 11
  49.      * or 15 seconds each time we wish to read data.  We observe that each
  50.      * ^INFO command returns at least one character and that when the ^INFO
  51.      * command is finally interpreted, all the information is sent out to
  52.      * the debugger port very quickly.  Consequently, we can wait a long
  53.      * time before reading the first character, but after reading the
  54.      * subsequent characters we wait a short time.
  55.      */
  56.     if (_FirstChar)
  57.         (void)alarm(300);    /* Wait 5 minutes maximum */
  58.     else
  59.     (void)alarm(3);
  60.     if (setjmp(Env)) {
  61.     (void)alarm(0);
  62.     return EOF;
  63.     }
  64.     c = getc(f);
  65.     (void)alarm(0);
  66.     _FirstChar = FALSE;
  67.     return c;
  68. }
  69.  
  70. static timeout()
  71. {
  72.     longjmp(Env, TRUE);
  73. }
  74.  
  75. void qmsmapfree(mapinfo)
  76. struct qmsmap    *mapinfo;
  77. {
  78.     struct qmsmap   *p;
  79.  
  80.     for (; mapinfo; mapinfo = p) {
  81.     if (mapinfo->data)
  82.         free(mapinfo->data);
  83.     p = mapinfo->next;
  84.     free((char *)mapinfo);
  85.     }
  86. }
  87.  
  88. void qmsovlfree(ovlinfo)
  89. struct qmsovl    *ovlinfo;
  90. {
  91.     struct qmsovl   *p;
  92.  
  93.     for (; ovlinfo; ovlinfo = p) {
  94.     p = ovlinfo->next;
  95.     free((char *)ovlinfo);
  96.     }
  97. }
  98.  
  99. void qmspfpfree(pfpinfo)
  100. struct qmspfp    *pfpinfo;
  101. {
  102.     struct qmspfp   *p;
  103.  
  104.     for (; pfpinfo; pfpinfo = p) {
  105.     if (pfpinfo->module)
  106.         free(pfpinfo->module);
  107.     p = pfpinfo->next;
  108.     free((char *)pfpinfo);
  109.     }
  110. }
  111.  
  112. void qmsopcfree(opcinfo)
  113. struct qmsopc    *opcinfo;
  114. {
  115.     struct optnode  *p1, *p2;
  116.  
  117.     for (p1 = opcinfo->OC1; p1; p1 = p2) {
  118.     p2 = p1->next;
  119.     free((char *)p1);
  120.     }
  121.     for (p1 = opcinfo->OC2; p1; p1 = p2) {
  122.     p2 = p1->next;
  123.     free((char *)p1);
  124.     }
  125.     for (p1 = opcinfo->OC3; p1; p1 = p2) {
  126.     p2 = p1->next;
  127.     free((char *)p1);
  128.     }
  129.     for (p1 = opcinfo->OC4; p1; p1 = p2) {
  130.     p2 = p1->next;
  131.     free((char *)p1);
  132.     }
  133.     for (p1 = opcinfo->OC5; p1; p1 = p2) {
  134.     p2 = p1->next;
  135.     free((char *)p1);
  136.     }
  137. }
  138.  
  139. void qmsfntfree(fntinfo)
  140. struct qmsfnt    *fntinfo;
  141. {
  142.     struct fontnode *p1, *p2;
  143.  
  144.     for (p1 = fntinfo->rom; p1; p1 = p2) {
  145.     p2 = p1->next;
  146.     free((char *)p1);
  147.     }
  148.     for (p1 = fntinfo->ram; p1; p1 = p2) {
  149.     p2 = p1->next;
  150.     free((char *)p1);
  151.     }
  152. }
  153.